package cn.zucc.edu.handyzucc.service.impl;

import cn.zucc.edu.handyzucc.dao.MaintenanceDao;
import cn.zucc.edu.handyzucc.entity.Maintenance;
import cn.zucc.edu.handyzucc.entity.MaintenanceExtend;
import cn.zucc.edu.handyzucc.service.MaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MaintenanceServiceImpl implements MaintenanceService {
    @Autowired
    private MaintenanceDao maintenanceDao;

    @Override
    public List<MaintenanceExtend> getAllMaintenance() {
        return maintenanceDao.getAllMaintenance();
    }

    @Override
    public List<Maintenance> getMaintenancesByDorm(Integer maintenance_dorm) {
        return maintenanceDao.getMaintenancesByDorm(maintenance_dorm);
    }

    @Override
    public boolean addMaintenance(Maintenance maintenance) {
        try {
            int effectedNum = maintenanceDao.addMaintenance(maintenance);
            if (effectedNum == 1)
                return true;
            else return false;
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }

    @Override
    public boolean deleteMaintenance(Integer maintenance_id) {
        try {
            int effectedNum = maintenanceDao.deleteMaintenance(maintenance_id);
            if (effectedNum == 1)
                return true;
            else return false;
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }

    @Override
    public boolean completeMaintenance(Integer maintenance_id) {
        try {
            int effectedNum = maintenanceDao.completeMaintenance(maintenance_id);
            if (effectedNum == 1)
                return true;
            else return false;
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }
}
